package com.dcits.account.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMVCConfig implements WebMvcConfigurer {

    private Logger log = LoggerFactory.getLogger(WebMVCConfig.class);

    @Autowired
    private LoginInterceptor loginInterceptor;

    /**
     * 无业务含义单纯的页面跳转控制器
     *
     * @param registry
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/register").setViewName("register");
        registry.addViewController("/login").setViewName("login");
        registry.addViewController("/").setViewName("login");
        registry.addViewController("/index").setViewName("indexold");
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        log.info("开始注入拦截器");
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**")
                .excludePathPatterns(
                        "/**/fonts/*",
                        "/**/*.css",
                        "/**/*.js",
                        "/**/*.png",
                        "/**/*.gif",
                        "/**/*.jpg",
                        "/**/*.jpeg",
                        "/**/*.JPG",
                        "/login",
                        "/register",
                        "/login/loginVerifyUserPhone/*",
                        "/login/verifyLogin",
                        "/doRegister",
                        "/"

                );

//            <mvc:exclude-mapping path="/admin/tologin"/>
//            <mvc:exclude-mapping path="/admin/login"/>
//            <mvc:exclude-mapping path="/admin/quit"/>
//            <mvc:exclude-mapping path="/**/*.jpg"/>
//            <mvc:exclude-mapping path="/**/*.jpeg"/>
    }
}
